package com.bee.test;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class IDPhotoMaker {

    private static final String filePath="/Users/xupei/dev/";
    public static void main(String[] args) {
        try {
            // 读取原始照片
            BufferedImage originalImage = ImageIO.read(new File(filePath+"original_photo.jpeg"));

            // 一寸照片的像素尺寸 (300 dpi)
            int width = 1181;
            int height = 1181;

            // 创建一寸蓝底照片
            BufferedImage blueBackgroundPhoto = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = blueBackgroundPhoto.createGraphics();

            // 设定蓝色背景
            g2d.setColor(Color.BLUE);
            g2d.fillRect(0, 0, width, height);

            // 将照片放在蓝色背景上
            int x = (width - originalImage.getWidth()) / 2;
            int y = (height - originalImage.getHeight()) / 2;
            g2d.drawImage(originalImage, x, y, null);

            g2d.dispose();

            // 保存一寸蓝底照片
            ImageIO.write(blueBackgroundPhoto, "jpg", new File(filePath+"blue_background_photo.jpg"));


            System.out.println("证件照制作完成！");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
